//
//  VideoTabelViewCell.m
//  B-72K
//
//  Created by sos on 16/3/7.
//  Copyright © 2016年 sos. All rights reserved.
//

#import "VideoTabelViewCell.h"
#import <Masonry.h>
#import "VideoModel.h"
#import <UIImageView+WebCache.h>
@implementation VideoTabelViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.image = [UIImageView new];
//        _image.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_image];
        
        
        self.title = [UILabel new];
//        _title.backgroundColor = [UIColor yellowColor];
        _title.font = [UIFont systemFontOfSize:14];
        _title.textColor = [UIColor whiteColor];
        _title.numberOfLines = 0;
        [_image addSubview:_title];
        
        
        self.durantionTime = [UILabel new];
//        _durantionTime.backgroundColor = [UIColor cyanColor];
        _durantionTime.font = [UIFont systemFontOfSize:10];
        _durantionTime.textColor = [UIColor whiteColor];
        [_image addSubview:_durantionTime];
    }
    
    return self;
    
    
}

-(void)layoutSubviews
{
     __weak __typeof(&*self)weakSelf = self;
//    _image.frame = CGRectMake(0, 0, 355, 200);
    
    [self.image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.mas_left).offset(0);
        make.top.equalTo(weakSelf.mas_top).offset(0);
        make.height.mas_equalTo(200);
        make.right.equalTo(weakSelf.mas_right).offset(0);
        
    }];
    
//    _title.frame = CGRectMake(10, 150, self.contentView.frame.size.width - 20, 40);
    [self.title mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.image.mas_top).offset(150);
        make.left.equalTo(weakSelf.image.mas_left).offset(10);
        make.right.equalTo(weakSelf.image.mas_right).offset(-10);
        make.height.mas_equalTo(40);

        
    }];
    
//    _durantionTime.frame = CGRectMake(self.contentView.frame.size.width - 50, 20, 40, 20);
    
    [self.durantionTime mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.image.mas_right).offset(0);
        make.left.equalTo(weakSelf.image.mas_right).offset(-50);
        make.top.equalTo(weakSelf.image.mas_top).offset(20);
        make.height.mas_equalTo(20);
        
    }];
    
}

-(void)setMm:(VideoModel *)mm
{
    
    _mm = mm;
    
    _title.text = mm.title;
    
    [_image sd_setImageWithURL:[NSURL URLWithString:mm.featureImg]];
    
    _durantionTime.text = mm.duration;

    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
